package io.renren.modules.demo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.renren.common.service.impl.CrudServiceImpl;
import io.renren.common.utils.ConvertUtils;
import io.renren.modules.demo.dao.DhGodssellInfoDao;
import io.renren.modules.demo.dto.DhGodsrentInfoDTO;
import io.renren.modules.demo.dto.DhGodssellInfoDTO;
import io.renren.modules.demo.entity.DhGodsrentInfoEntity;
import io.renren.modules.demo.entity.DhGodssellInfoEntity;
import io.renren.modules.demo.service.DhGodssellInfoService;
import io.renren.modules.sys.dto.SysUserDTO;
import io.renren.modules.sys.service.SysUserService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 
 *
 * @author Mark sunlightcs@gmail.com
 * @since 1.0.0 2023-03-25
 */
@Service
public class DhGodssellInfoServiceImpl extends CrudServiceImpl<DhGodssellInfoDao, DhGodssellInfoEntity, DhGodssellInfoDTO> implements DhGodssellInfoService {

    @Autowired
    private SysUserService sysUserService;

    @Autowired
    private DhGodssellInfoDao dhGodssellInfoDao;

    @Override
    public QueryWrapper<DhGodssellInfoEntity> getWrapper(Map<String, Object> params){
        String id = (String)params.get("id");

        QueryWrapper<DhGodssellInfoEntity> wrapper = new QueryWrapper<>();
        wrapper.eq(StringUtils.isNotBlank(id), "id", id);

        return wrapper;
    }

    /**
     * 获取当前登录账号的购买物品信息
     * @param userId
     * @return
     */
    @Override
    public List<DhGodssellInfoDTO> getSellInfoDataList(Long userId) {
        SysUserDTO sysUserDTO = sysUserService.getCLOUusername(userId);
        Integer username = Integer.valueOf(sysUserDTO.getUsername());
        LambdaQueryWrapper<DhGodssellInfoEntity> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.select().eq(DhGodssellInfoEntity::getUserId,username);
        List<DhGodssellInfoEntity> dhGodssellInfoEntities = dhGodssellInfoDao.selectList(queryWrapper);
        return ConvertUtils.sourceToTarget(dhGodssellInfoEntities, DhGodssellInfoDTO.class);
    }
}